/**
 *  @author phi
 *  @memo   
 */
#pragma once

#include "tmlib.h"
#include "game-app-manager.h"

class EventDispatcherTest : public Application
{
public :
    void initialize()
    {
        tmlib::display::DisplayObject* obj = NULL;

        // mouse down
        {
            obj = _root.addChild( new tmlib::display::DisplayObjectContainer() );

            obj->x(320-50).y(240-50).width(100).height(100);
            obj->addEventListener(events::EventInfo::MOUSE_DOWN, onMouseEvent);
            obj->addEventListener(events::EventInfo::MOUSE_UP, onMouseEvent);
            obj->addEventListener(events::EventInfo::MOUSE_OVER, onMouseEvent);
            obj->addEventListener(events::EventInfo::MOUSE_OUT, onMouseEvent);
        }

    }

    void finalize()
    {
    }

    void update()
    {
        _root.update();
    }
    void draw()
    {
        _root.draw();
    }

    static bool onMouseEvent(events::Event* e)
    {
        tmlib::display::InteractiveObject* obj = (tmlib::display::InteractiveObject*)(e->getTarget());

        switch (e->getType())
        {
            case events::EventInfo::MOUSE_DOWN :
                cout << "Mouse Down" << endl;
                obj->scaleX(1.25);
                obj->scaleY(1.25);
                break;
            case events::EventInfo::MOUSE_UP :
                cout << "Mouse Up" << endl;
                obj->scaleX(1);
                obj->scaleY(1);
                break;
            case events::EventInfo::MOUSE_OVER :
                cout << "Mouse Over" << endl;
                obj->setColor(1.0f, 0.0f, 0.0f, 1.0f);
                break;
            case events::EventInfo::MOUSE_OUT :
                cout << "Mouse Out" << endl;
                obj->setColor(1.0f, 1.0f, 1.0f, 1.0f);
                break;
        }

        return true;
    }

};